<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <meta name="twitter:site" content="@metroui">
    <meta name="twitter:creator" content="@pimenov_sergey">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:title" content="Metro 4 Components Library">
    <meta name="twitter:description" content="Metro 4 is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with responsive grid system, extensive prebuilt components, and powerful plugins  .">
    <meta name="twitter:image" content="https://metroui.org.ua/images/m4-logo-social.png">

    <meta property="og:url" content="https://metroui.org.ua/v4/index.html">
    <meta property="og:title" content="Metro 4 Components Library">
    <meta property="og:description" content="Metro 4 is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with responsive grid system, extensive prebuilt components, and powerful plugins  .">
    <meta property="og:type" content="website">
    <meta property="og:image" content="https://metroui.org.ua/images/m4-logo-social.png">
    <meta property="og:image:secure_url" content="https://metroui.org.ua/images/m4-logo-social.png">
    <meta property="og:image:type" content="image/png">
    <meta property="og:image:width" content="968">
    <meta property="og:image:height" content="504">

    <meta name="author" content="Sergey Pimenov">
    <meta name="description" content="The most popular HTML, CSS, and JS library in Metro style.">
    <meta name="keywords" content="HTML, CSS, JS, Metro, CSS3, Javascript, HTML5, UI, Library, Web, Development, Framework">

    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="icon" href="favicon.ico" type="image/x-icon">

    <link href="metro/css/metro-all.css?ver=@@b-version" rel="stylesheet">
    <link href="highlight/styles/github.css" rel="stylesheet">
    <link href="docsearch/docsearch.min.css" rel="stylesheet">
    <link href="css/site.css" rel="stylesheet">

    <title>Chat - Metro 4 :: Popular HTML, CSS and JS library</title>
</head>
<body class="m4-cloak">

<header data-role="html-container" data-insert-mode="replace" data-html-source="header.html"></header>

<div data-role="html-container" data-insert-mode="replace" data-html-source="sidebar-menu.html"></div>

<div class="container-fluid docs-content">

    <div class="row flex-xl-nowrap">

            <div class="d-none d-block-xl cell-xl-2 order-2 border-left bd-light toc-wrapper">
                <h5>Table of contents</h5>
                <hr/>
                <ul class="toc-nav">
                    <li class="toc-entry"><a href="#">Chat</a></li>
                    <li class="toc-entry"><a href="#_chat_about">About</a></li>
                    <li class="toc-entry"><a href="#_chat_options">Options</a></li>
                    <li class="toc-entry"><a href="#_chat_events">Events</a></li>
                    <li class="toc-entry"><a href="#_chat_methods">Methods</a></li>
                    <li class="toc-entry"><a href="#_chat_customize">Customize</a></li>
                    <li class="toc-entry"><a href="#_chat_message">Message</a></li>
                </ul>

            </div>

            <main class="cell-xl-10 order-1 pr-1-sx pl-1-sx pr-5-md pl-5-md">
                <div class="place-right d-none d-block-lg" style="width: 200px;">
                    <img src="images/logo.png" class="w-100" alt="">
                </div>

                <h1>Chat</h1>
                <p class="text-leader">
                    Metro 4 implements component to create simple chat.
                </p>

                <!-- ads-html -->

                <h3 id="_chat_about">About</h3>
                <p>
                    In Metro 4 you can create simple chat.
                </p>
                <div class="example">
                    <div id="chat" class="mx-auto"
                         data-role="chat"
                         data-width="300"
                         data-height="400"
                         data-title="Direct chat"
                         data-cls-send-button="success"
                         data-random-color="true"
                         data-welcome="Welcome to Metro 4 chat component!"
                         data-cls-message-left="default"
                         data-cls-message-right="success"
                         data-on-send="sendMessage"
                         data-avatar=""
                         data-readonly="false"
                    ></div>
                </div>

                <h3>Create chat</h3>
                <p>
                    To create simple interface for your chat you must create <code>container</code> with role <code>chat</code> and set size roy you chat. That's all.
                </p>
                <div class="example">
                    <div data-role="chat" data-width="300" data-height="400" class="mx-auto"></div>
                </div>
                <pre><code>
                    &lt;div
                      data-role="chat"
                      data-width="300"
                      data-height="400"
                    &gt;&lt;/div&gt;
                </code></pre>

                <h3 id="_chat_options">Options</h3>
                <table class="table cell-border table-border options-table mt-4" data-role="table" data-horizontal-scroll="true" data-show-search="false" data-show-pagination="false" data-show-rows-steps="false" data-show-table-info="false">
                    <thead>
                    <tr>
                        <th>Option</th>
                        <th>Data-*</th>
                        <th>Default</th>
                        <th>Desc</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><code>timeFormat</code></td>
                        <td><code>data-time-format</code></td>
                        <td>%d %b %l:%M %p</td>
                        <td>Message time format. More about <a href="dateformat.html">date-time formats</a></td>
                    </tr>
                    <tr>
                        <td><code>inputTimeFormat</code></td>
                        <td><code>data-input-time-format</code></td>
                        <td>%m-%d-%y</td>
                        <td>Message input time format. More about <a href="dateformat.html">date-time formats</a></td>
                    </tr>
                    <tr>
                        <td><code>name</code></td>
                        <td><code>data-name</code></td>
                        <td>John Doe</td>
                        <td>Receiver name</td>
                    </tr>
                    <tr>
                        <td><code>avatar</code></td>
                        <td><code>data-avatar</code></td>
                        <td></td>
                        <td>Receiver avatar. Must be string with image source (used for img src attribute)</td>
                    </tr>
                    <tr>
                        <td><code>welcome</code></td>
                        <td><code>data-welcome</code></td>
                        <td>null</td>
                        <td>Welcome message</td>
                    </tr>
                    <tr>
                        <td><code>title</code></td>
                        <td><code>data-title</code></td>
                        <td>null</td>
                        <td>Chat title</td>
                    </tr>
                    <tr>
                        <td><code>width</code></td>
                        <td><code>data-width</code></td>
                        <td>100%</td>
                        <td>Chat width</td>
                    </tr>
                    <tr>
                        <td><code>height</code></td>
                        <td><code>data-height</code></td>
                        <td>auto</td>
                        <td>Chat height</td>
                    </tr>
                    <tr>
                        <td><code>randomColor</code></td>
                        <td><code>data-random-color</code></td>
                        <td>false</td>
                        <td>If true, messages colorized with random color from predefined colors</td>
                    </tr>
                    <tr>
                        <td><code>messages</code></td>
                        <td><code>data-messages</code></td>
                        <td>null</td>
                        <td>Object with initialization messages</td>
                    </tr>
                    <tr>
                        <td><code>sendButtonTitle</code></td>
                        <td><code>data-send-button-title</code></td>
                        <td>Send</td>
                        <td>Title for Send button</td>
                    </tr>
                    </tbody>
                </table>

                <h3 id="_chat_events">Events</h3>
                <table class="table cell-border table-border options-table mt-4" data-role="table" data-horizontal-scroll="true" data-show-search="false" data-show-pagination="false" data-show-rows-steps="false" data-show-table-info="false">
                    <thead>
                    <tr>
                        <th>Event</th>
                        <th>Data-*</th>
                        <th>Desc</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><code>onMessage(msg)</code></td>
                        <td><code>data-on-message</code></td>
                        <td>Fired when message added to chat</td>
                    </tr>
                    <tr>
                        <td><code>onSend(msg)</code></td>
                        <td><code>data-on-send</code></td>
                        <td>Fired when user click on Send button</td>
                    </tr>
                    <tr>
                        <td><code>onChatCreate</code></td>
                        <td><code>data-on-chat-create</code></td>
                        <td>Fired when chat was created</td>
                    </tr>
                    </tbody>
                </table>

                <h3 id="_chat_methods">Methods</h3>
                <table class="table cell-border table-border options-table mt-4" data-role="table" data-horizontal-scroll="true" data-show-search="false" data-show-pagination="false" data-show-rows-steps="false" data-show-table-info="false">
                    <thead>
                    <tr>
                        <th>Method</th>
                        <th>Desc</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><code>clear()</code></td>
                        <td>Clear all message</td>
                    </tr>
                    <tr>
                        <td><code>add(msg)</code></td>
                        <td>Add message to chat</td>
                    </tr>
                    <tr>
                        <td><code>addMessages(messages)</code></td>
                        <td>Add messages to chat</td>
                    </tr>
                    <tr>
                        <td><code>delMessage(msg_id)</code></td>
                        <td>Del message from chat</td>
                    </tr>
                    <tr>
                        <td><code>updMessage(msg)</code></td>
                        <td>Update message on chat</td>
                    </tr>
                    </tbody>
                </table>

                <h3 id="_chat_customize">Customize</h3>
                <p>
                    You can customize chat with special attributes.
                </p>
                <table class="table cell-border table-border options-table mt-4" data-role="table" data-horizontal-scroll="true" data-show-search="false" data-show-pagination="false" data-show-rows-steps="false" data-show-table-info="false">
                    <thead>
                    <tr>
                        <th>Attr</th>
                        <th>Data-*</th>
                        <th>Desc</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><code>clsChat</code></td>
                        <td><code>data-cls-chat</code></td>
                        <td>Class for chat component</td>
                    </tr>
                    <tr>
                        <td><code>clsName</code></td>
                        <td><code>data-cls-name</code></td>
                        <td>Class for sender or receiver name</td>
                    </tr>
                    <tr>
                        <td><code>clsTime</code></td>
                        <td><code>data-cls-time</code></td>
                        <td>Class for message time</td>
                    </tr>
                    <tr>
                        <td><code>clsInput</code></td>
                        <td><code>data-cls-input</code></td>
                        <td>Class for chat input control</td>
                    </tr>
                    <tr>
                        <td><code>clsSendButton</code></td>
                        <td><code>data-cls-send-button</code></td>
                        <td>Class for send button</td>
                    </tr>
                    <tr>
                        <td><code>clsMessageLeft</code></td>
                        <td><code>data-cls-message-left</code></td>
                        <td>Class for left message</td>
                    </tr>
                    <tr>
                        <td><code>clsMessageRight</code></td>
                        <td><code>data-cls-message-right</code></td>
                        <td>Class for right message</td>
                    </tr>
                    </tbody>
                </table>

                <h3 id="_chat_message">Message structure</h3>
                <p>
                    Chat message is a plain object.
                </p>
                <pre><code>
                    message = {
                        id,
                        name,
                        time,
                        avatar,
                        position
                    }
                </code></pre>

                <table class="table cell-border table-border options-table mt-4" data-role="table" data-horizontal-scroll="true" data-show-search="false" data-show-pagination="false" data-show-rows-steps="false" data-show-table-info="false">
                    <thead>
                    <tr>
                        <th>Property</th>
                        <th>Type</th>
                        <th>Desc</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td><code>id</code></td>
                        <td><code>any</code></td>
                        <td>Message unique id</td>
                    </tr>
                    <tr>
                        <td><code>name</code></td>
                        <td><code>string</code></td>
                        <td>Sender name</td>
                    </tr>
                    <tr>
                        <td><code>time</code></td>
                        <td>valid ECMA script datetime string</td>
                        <td>Message time</td>
                    </tr>
                    <tr>
                        <td><code>avatar</code></td>
                        <td><code>uri</code></td>
                        <td>Sender avatar, used for img src attribute</td>
                    </tr>
                    <tr>
                        <td><code>position</code></td>
                        <td><code>string</code></td>
                        <td>left or right</td>
                    </tr>
                    </tbody>
                </table>
            </main>
        </div>

    </div>

    <script src="docsearch/docsearch.min.js"></script>


    <script src="metro/js/metro.js?ver=@@b-version"></script>
    <script src="highlight/highlight.pack.js"></script>
    <script src="js/clipboard.min.js"></script>
    <script src="js/site.js"></script>
<script>
    var messages = [
        "Confucius says: vision and om."
        , "Be unconditional."
        , "Scholars, winds, and inward lovers will always protect them."
        , "The meditation of hurting yogis is closest."
        , "One mediocre silence i give you: meet each other."
        , "You have to preach, and love blessing by your rising."
        , "Acceptance, resurrection and a boundless great unknown."
        , "Demissios mori, tanquam gratis buxum."
        , "Aye, ah."
        , "Stutter calmly like a salty dubloon."
        , "Devastation at the holodeck was the rumour of faith, avoided to a solid planet."
        , "Solitudos volare, tanquam brevis torquis."
        , "When mashing small shrimps, be sure they are room temperature."
        , "Try fluffing cheesecake garnished with cocktail sauce, blended with onion powder."
        , "You have to sit, and know core by your balancing."
        , "Gar, mighty lubber. you won't crush the pacific ocean."
    ];

    var opponent = {
        name: "Jackie Chan",
        avatar:  "images/jek_vorobey.jpg"
    };

    function sendMessage(msg){
        var chat = $("#chat").data("chat");
        setTimeout(function(){
            var _m = {
                name: opponent.name,
                time: (new Date()),
                avatar: opponent.avatar,
                text: messages[$.random(0, messages.length - 1)],
                position: "left"
            };
            chat.add(_m);
        }, $.random(1000, 3000));
    }
</script>

    <!-- ads-script -->
    <!-- ga-script -->
    <!-- hit-ua -->
</body>
</html>